<?php

require_once WP_PLUGIN_DIR . '/diapucp-events/defines.php' ;
require_once DPEM_SMB_PATH . '/smb_basefield.php' ;

class smartmeta_checkbox extends smb_basefieldbox {
   public function  __construct($fields){
        $this->set_fields($fields);
        $this->set_inputid( $fields['id'] . '_checkbox_field' );
   }

   public static function build_me( $fields, &$new_field_object ){
        $new_field_object = new smartmeta_checkbox($fields);
   }

   public function show(){
        $value = $this->fetch_value();
        ?>
            <td>
                <label for="<?php echo $this->inputid; ?>"><?php echo $this->fields['name']; ?></label>
            </td>
            <td><em>&nbsp;&nbsp;</em>
                <input type="checkbox"
                       name="<?php echo $this->inputid; ?>"
                       id="<?php echo $this->inputid; ?>"
                       <?php checked($value, 'true'); ?>
                       value="true"
                />
            </td>
        <?php
   }

   public function save($post_id){
       if ( !isset( $_POST[$this->inputid] ) ){
           smb_basefieldbox::set($this->fields['id'], 'false', $post_id);
       } else {
           smb_basefieldbox::set($this->fields['id'], 'true',$post_id);
       }
   }
}

?>